home *** CD-ROM | disk | FTP | other *** search
- /*
- GetClicks.c
- waits for a mouse click, and then counts clicks (e.g. double-click, triple-click). Each
- click must arrive within the allowed double-click time of the previous,
- as set in the Control Panel. Returns the number of clicks, 1 or more.
- Calls PrintfExit if the user hits Command-period.
- Calls SndStop1() immediately after the first click on the assumption that the user is
- responding to the sound and should get the feedback of knowing that the computer knows
- s/he's now responding. SndStop1() is innocuous if in fact no sound is playing.
-
- HISTORY:
- 4/30/88 dgp wrote it
- 3/31/90 dgp cleaned up code and documentation.
- 8/24/91 dgp Made compatible with THINK C 5.0.
- 3/30/91 dgp use SndStop1() instead of obsolete Sound Driver.
- 1/25/93 dgp removed obsolete support for THINK C 4.
- 4/29/95 dgp added GetNextEventOrQuit(), so that we can abort at any time by hitting Command-.
- 6/18/95 dgp changed abort() to exit(1) for better compatibility with CW atexit().
- 6/6/96 dgp replaced US-only test by IsCmdPeriod() test, which will work internationally.
- 6/7/96 dhb use PrintfExit so it will work in a MEX file.
- dhb fixed GetNextEventOrQuit so it compiles. It referenced an undefined variable.
- 2/3/97 dgp added WaittNextEventOrQuit. Removed mention of "GetClicks: ", since
- this may be called from other functions that are unrelated to GetClicks, e.g.
- from WaitSecs() in TIMER.src.c in David's Psychophysics Toolbox
- 2/9/97 dgp dropped need for IsCmdPeriod.c, but now require System 7.
- 3/10/97 dgp use the new CommandPeriod.c, which doesn't discard keyDown events.
- */
- #include "VideoToolbox.h"
- // GetNextEventOrQuit is in CommandPeriod.c
-
- short GetClicks(void)
- {
- long ticks;
- EventRecord event;
- short clicks;
-
- clicks=0;
- while(!GetNextEventOrQuit(mDownMask,&event)) ;
- SndStop1(); /* Stop sound on first click */
- clicks++;
- ticks=TickCount()+GetDblTime();
- while(!GetNextEventOrQuit(mUpMask,&event)) ;
- while(TickCount()<ticks){ /* wait as long as possible for another click */
- if(GetNextEventOrQuit(mDownMask,&event)){
- clicks++;
- ticks=TickCount()+GetDblTime();
- while(!GetNextEventOrQuit(mUpMask,&event)) ;
- }
- }
- return clicks;
- }
-